package org.tgcloud.group.web.controller.manager;

import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.tgcloud.group.core.APPResultMessage;
import org.tgcloud.group.core.StringUtil;
import org.tgcloud.group.core.custom.Permissions;
import org.tgcloud.group.core.session.Session;
import org.tgcloud.group.service.manager.SysManageService;
import org.tgcloud.group.web.controller.dto.sys.SysLabelListDTO;
import org.tgcloud.group.web.controller.req.sysLabel.*;

import java.util.List;

/**
 * @author: zhy
 * @description: 系统管理相关接口
 * @create: 2023年08月17日 13:44
 * @return
 */
@Api(tags = "系统管理相关接口")
@RestController
@RequestMapping("/manager/pc/user")
@EnableAutoConfiguration
public class SysManageController extends ManageAPPBaseController {

    @Autowired
    private SysManageService sysManageService;

    @ApiOperation(value = "分类值列表")
    @ApiImplicitParams({
    })
    @ApiResponses({
            @ApiResponse(code = 2000, message = "出现异常，及时通知后台")
    })
    @ResponseBody
    @PostMapping(value = "/getSysLabelValueManageList")
    public APPResultMessage getSysLabelValueManageList(@RequestBody SysLabelIdReq req,
                                                       @ModelAttribute("session") Session session) {
        return sysManageService.getSysLabelValueManageList(req);
    }

    @ApiOperation(value = "小组列表")
    @ApiImplicitParams({
    })
    @ApiResponses({
            @ApiResponse(code = 2000, message = "出现异常，及时通知后台")
    })
    @ResponseBody
    @PostMapping(value = "/selectAllGroup")
    public APPResultMessage selectAllGroup(@ModelAttribute("session") Session session,
                                           @RequestParam(required = false) Integer targetId
                                           ) {
        return sysManageService.selectAllGroup(targetId);
    }
    //

    @ApiOperation(value = "分类列表")
    @ApiImplicitParams({
    })
    @ApiResponses({
            @ApiResponse(code = 2000, message = "出现异常，及时通知后台")
    })
    @ResponseBody
    @PostMapping(value = "/getSysLabelManageList")
    public APPResultMessage<Object, SysLabelListDTO> getSysLabelManageList(@RequestBody SysLabelPageReq req) {
        return sysManageService.getSysLabelManageList(req);
    }



    @Permissions("sysLabel:add")
    @ApiOperation(value = "添加分类值")
    @ApiImplicitParams({
    })
    @ApiResponses({
            @ApiResponse(code = 2000, message = "出现异常，及时通知后台")
    })
    @ResponseBody
    @PostMapping(value = "/doAddSysLabelValue")
    public APPResultMessage<Object, List> doAddSysLabelValue(@RequestBody SysLabelValueAddReq req,
                                                             @ModelAttribute("session") Session session) {
        if (req.getSysLabelId() == null || StringUtil.isBlank(req.getSysValueName())){
            return APPResultMessage.MISS_PARAMETER();
        }
        return sysManageService.doAddSysLabelValue(req);
    }

    @Permissions("sysLabel:edit")
    @ApiOperation(value = "修改分类值")
    @ApiImplicitParams({
    })
    @ApiResponses({
            @ApiResponse(code = 2000, message = "出现异常，及时通知后台")
    })
    @ResponseBody
    @PostMapping(value = "/doEditSysLabelValue")
    public APPResultMessage<Object, List> doEditSysLabelValue(@RequestBody SysLabelValueEditReq req,
                                                              @ModelAttribute("session") Session session) {
        if (req.getSysLabelId() == null || StringUtil.isBlank(req.getSysValueName()) || req.getValueId() == null){
            return APPResultMessage.MISS_PARAMETER();
        }
        return sysManageService.doEditSysLabelValue(req);
    }

    @Permissions("sysLabel:del")
    @ApiOperation(value = "删除分类值")
    @ApiImplicitParams({
    })
    @ApiResponses({
            @ApiResponse(code = 2000, message = "出现异常，及时通知后台")
    })
    @ResponseBody
    @PostMapping(value = "/doDelSysLabelValue")
    public APPResultMessage doDelSysLabelValue(@RequestBody SysLabelIdsReq req,
                                               @ModelAttribute("session") Session session) {
        return sysManageService.doDelSysLabelValue(req);
    }





    @ApiOperation(value = "上传文件")
    @ApiImplicitParams({
    })
    @ApiResponses({
            @ApiResponse(code = 2000, message = "出现异常，及时通知后台")
    })
    @ResponseBody
    @PostMapping(value = "/uploadFile")
    public APPResultMessage doUploadFile(@RequestParam(value = "file") MultipartFile file,
                                         @ModelAttribute("session") Session session) throws Exception {
        return sysManageService.doUploadFile(file);
    }



    /**
     * 获取省列表
     *
     * @return
     */
    @ApiOperation(value = "获取省列表")
    @ApiImplicitParams({
    })
    @ApiResponses({
            @ApiResponse(code = 2000, message = "出现异常，及时通知后台")
    })
    @ResponseBody
    @PostMapping(value = "/get_province")
    public APPResultMessage get_province() {
        return sysManageService.selectProvince();
    }

    /**
     * 获取市列表
     *
     * @return
     */
    @ApiOperation(value = "获取市列表")
    @ApiImplicitParams({
    })
    @ApiResponses({
            @ApiResponse(code = 2000, message = "出现异常，及时通知后台")
    })
    @ResponseBody
    @PostMapping(value = "/get_city")
    public APPResultMessage get_city(@RequestParam String province) {
        return sysManageService.selectCity(province);
    }

    /**
     * 获取区县列表
     *
     * @return
     */
    @ApiOperation(value = "获取区县列表")
    @ApiImplicitParams({
    })
    @ApiResponses({
            @ApiResponse(code = 2000, message = "出现异常，及时通知后台")
    })
    @ResponseBody
    @PostMapping(value = "/get_district")
    public APPResultMessage get_district(@RequestParam String city) {
        return sysManageService.selectDistrict(city);
    }


}
